class CustomerLevelsController < ApplicationController
  before_action :set_menu

  def index
    @submenu = :customer_lev
    @title = '客户级别'
    @customer_levels = CustomerLevel.all
  end

  def new
    @customer_level = CustomerLevel.new
  end

  def create
    @customer_level = CustomerLevel.new post_params
    if @customer_level.save
      redirect_to customer_levels_path
    else
      render :action => 'new'
    end
  end

  def edit
    @customer_level = CustomerLevel.find params[:id]
  end

  def update
    @customer_level = CustomerLevel.find params[:id]
    if @customer_level.update_attributes post_params
      redirect_to customer_levels_path
    else
      render :action => 'edit'
    end
  end

  def destroy
    @customer_level = CustomerLevel.find params[:id]
    @customer_level.destroy
    redirect_to customer_levels_path
  end


  def post_params
    params.require(:customer_level).permit(*%w(name))
  end

  private
  def set_menu
    @mainmenu = :customer
  end
end
